home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UDebug.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  4.0 KB  |  190 lines  |  [TEXT/MPS ]

  1. #ifndef __TYPES__
  2. #include <Types.h>
  3. #endif
  4.  
  5. #ifndef __IOCTL__
  6. #include <IOCtl.h>
  7. #endif
  8.  
  9. #ifndef __FCNTL__
  10. #include <FCntl.h>
  11. #endif
  12.  
  13.  
  14. #ifndef __STRINGS__
  15. #include <Strings.h>
  16. #endif
  17.  
  18. #ifndef __PROCESSES__
  19. #include <Processes.h>
  20. #endif
  21.  
  22. #ifndef __UFAILURE__
  23. #include <UFailure.h>
  24. #endif
  25.  
  26. typedef long(* GetProcPtr)(void* buffer,
  27.                            long count);
  28. typedef void(* PutProcPtr)(void* buffer,
  29.                            long count);
  30.  
  31. extern "C"
  32. {
  33.     extern long DevClose(long iop);
  34.     extern long DevIoctl(long iop,
  35.                          long cmd,
  36.                          void* arg);
  37.     extern long DevFAccess(char* fName,
  38.                            long cmd,
  39.                            void* arg);
  40.     extern long DevRead(long iop);
  41.     extern long DevWrite(long iop);
  42. }
  43.  
  44.  
  45. extern pascal Boolean IsFrontProcess(void);
  46. extern pascal GetProcPtr SetGetProc(GetProcPtr theGetProc);
  47. extern pascal PutProcPtr SetPutProc(PutProcPtr thePutProc);
  48.  
  49. // Global declarations
  50. extern Boolean pCanEnterDebugger;
  51. extern long pUDebugInitialized;
  52. extern long pSegTable;
  53. extern Str255 pFileName;
  54.  
  55.  
  56. // Global storage
  57. Boolean pCanEnterDebugger = FALSE;                // Boolean: Debugger can be entered
  58. long pUDebugInitialized = 0;                    // Boolean: if Trace unit is inited
  59. long pSegTable = 0;                                //  HandleListHandle
  60.  
  61. GetProcPtr pGetProc = NULL;                        // Address of the PASCAL Proc to Handle Read requests
  62. // Function DEVGETTEXT(textBuf: Ptr, byteCount: longint): longint;
  63. PutProcPtr pPutProc = NULL;                        // Address of the PASCAL Proc to Handle WriteLn requests
  64. // Procedure DEVPUTTEXT(textBuf: Ptr, byteCount: longint);
  65.  
  66. Str255 pFileName;                                // Name of the file to intercept
  67. //--------------------------------------------------------------------------------------------------
  68. #pragma segment Main
  69.  
  70. pascal GetProcPtr SetGetProc(GetProcPtr theGetProc)
  71. {
  72.     GetProcPtr returnProc = pGetProc;
  73.     pGetProc = theGetProc;
  74.     return returnProc;
  75. }
  76.  
  77. //--------------------------------------------------------------------------------------------------
  78. #pragma segment Main
  79.  
  80. pascal PutProcPtr SetPutProc(PutProcPtr thePutProc)
  81. {
  82.     PutProcPtr returnProc = pPutProc;
  83.     pPutProc = thePutProc;
  84.     return returnProc;
  85. }
  86.  
  87. //--------------------------------------------------------------------------------------------------
  88. #pragma segment Main
  89. long DevClose(long)
  90. {
  91.     return 0;
  92. }
  93.  
  94.  
  95. //--------------------------------------------------------------------------------------------------
  96. #pragma segment Main
  97.  
  98. long DevIoctl(long,
  99.               long cmd,
  100.               void*)
  101. {
  102.     switch (cmd)
  103.     {
  104.         case FIOINTERACTIVE:
  105.         case TIOFLUSH:
  106.             return 0;
  107.  
  108.         default:
  109.             return -1;
  110.     }
  111. }
  112.  
  113.  
  114. //--------------------------------------------------------------------------------------------------
  115. #pragma segment Main
  116.  
  117. long DevFAccess(char* fName,
  118.                 long cmd,
  119.                 void*)
  120. {
  121. # define CaseSensitive            TRUE
  122. # define DiacritSensitive        TRUE
  123.  
  124.     if (EqualString(Str255(fName), pFileName, !CaseSensitive, DiacritSensitive))
  125.         switch (cmd)
  126.         {
  127.             case F_OPEN:
  128.                 return 0;
  129.  
  130.             default:
  131.                 return -1;
  132.         }
  133.     else
  134.         return -1;
  135. }
  136.  
  137.  
  138.  
  139. // !!! Hopefully we can find a real interface for this someday or else do away with it entirely.
  140.  
  141. struct IOPort
  142. {
  143.     unsigned char filler[12];
  144.     Ptr bufp;
  145.     long count;
  146. };
  147.  
  148. //--------------------------------------------------------------------------------------------------
  149. #pragma segment Main
  150.  
  151. long DevRead(long iop)
  152. {
  153.     IOPort * iopPtr = (IOPort *)iop;
  154.     long bytesRead;
  155.  
  156.     bytesRead = pGetProc(iopPtr->bufp, iopPtr->count);
  157.     iopPtr->bufp += bytesRead;
  158.     iopPtr->count -= bytesRead;
  159.     return 0;
  160. }
  161.  
  162. //--------------------------------------------------------------------------------------------------
  163. #pragma segment Main
  164.  
  165. long DevWrite(long iop)
  166. {
  167.     IOPort * iopPtr = (IOPort *)iop;
  168.  
  169.     pPutProc(iopPtr->bufp, iopPtr->count);
  170.     iopPtr->count -= 0;
  171.     return 0;
  172. }
  173.  
  174.  
  175. //--------------------------------------------------------------------------------------------------
  176. #pragma segment Main
  177.  
  178. pascal Boolean IsFrontProcess(void)
  179. {
  180.     ProcessSerialNumber frontPSN;
  181.     ProcessSerialNumber applicationPSN;
  182.     Boolean result;
  183.  
  184.  
  185.     FailOSErr(GetCurrentProcess(applicationPSN));
  186.     FailOSErr(GetFrontProcess(frontPSN));
  187.     FailOSErr(SameProcess(frontPSN, applicationPSN, result));
  188.     return result;
  189. }
  190.